﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class View_UpdateJob : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsAdmin.Admin();
        this.btnSubmit.Attributes.Add("onclick", "javascript:succShow();");

        if (!Page.IsPostBack)
        {
            int id = Convert.ToInt32(Session["JobId"].ToString());
            string sql = "select * from jobInfo where id="+id;
            DataSet ds = dao.getDs(sql);
            foreach (DataRow dr in ds.Tables["message"].Rows)
            {
                this.txtJobName.Text = dr["jobName"].ToString();
                this.drpType.SelectedValue = dr["jobtype"].ToString();
                this.txtSalary.Text = dr["jobsalary"].ToString();
                this.txtNumber.Text = dr["jobnumber"].ToString();
                this.drpDiploma.SelectedValue = dr["jobdiploma"].ToString();
                this.drpSex.SelectedValue = dr["jobsex"].ToString();
                this.DateTimePicker1.Text = dr["jobbegintime"].ToString();
                this.DateTimePicker2.Text = dr["jobstoptime"].ToString();
                this.FCKeditor1.Value = dr["jobrequest"].ToString();
            }
        }
    }
    //修改
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int id =Convert.ToInt32(Session["JobId"].ToString());
        string jobName = this.txtJobName.Text;
        string type = this.drpType.SelectedValue.ToString();
        string salary = this.txtSalary.Text;
        int number = Convert.ToInt32(this.txtNumber.Text);
        string diploma = this.drpDiploma.SelectedValue.ToString();
        string sex = this.drpSex.SelectedValue.ToString();

        DateTime tt = Convert.ToDateTime(this.DateTimePicker1.Text.ToString());
        string beginTime = tt.ToShortDateString();

        string stopTime = "";
        string time = this.DateTimePicker2.Text;
        if (time.Equals("长期招聘"))
        {
            stopTime = time;
        }
        else
        {
            DateTime tt1 = Convert.ToDateTime(this.DateTimePicker2.Text);
            stopTime = tt1.ToShortDateString();
        }

        string request = this.FCKeditor1.Value;

        string sql = "update jobInfo set jobName='" + jobName + "',jobType='" + type + "',jobsalary='" + salary + "',jobNumber=" + number + ",jobdiploma='"
                        +diploma+"',jobsex='"+sex+"',jobBeginTime='"+beginTime+"',jobStopTime='"+stopTime+"',jobRequest='"+request+"' where id="+id;
        
        if (dao.getComm(sql) != 0)
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('修改成功');</script>");
            Server.Transfer("jobMessage.aspx");
        }
        else
        {
            RegisterStartupScript("check", "<script language='javascript'>alert('修改失败');</script>");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("jobMessage.aspx");
    }
}
